
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:reabamshengchan/src/reabam/operation/rb_config.dart';
import 'package:xsdk_flutter/xsdk/xsdk_flutter_package.dart';

/*
webview
 */
class MainWebViewStatePage extends XPageWebViewState{


  MainWebViewStatePage(
      {
        super.desktopNewWindowTitle='生产端'
      }
      );

  @override
  String getWebUrl() {
    return RBConfigs.h5Url;
  }

  @override
  void onCreate() {
    super.onCreate();
  }


  @override
  void onDestroy() {
    super.onDestroy();
  }

  @override
  void onStart() {
    XFlutterUtils.setScreenOrientation(false);
    XFlutterUtils.setSystemStatusBar(false);
    //保持设备唤醒状态
    XFlutterUtils.keepWakelock();
  }


  @override
  Future<void> handleReceiveJsSendMsg(String jsonStr) async {
  }

  //加载失败,是否显示自定义提示widget,注意: 只支持android,iOS,windows, 不支持mac(api没有失败通知);
  bool isWebViewLoadFailShowCustomWidget=false;
  //
  @override
  void onNotifyWebViewLoadUrlError(int? errorCode, String? description, String? failingUrl) {
    XLogUtils.printLog("---webview加载url失败通知: failingUrl=$failingUrl");
    setState(() {
      isWebViewLoadFailShowCustomWidget=true;
    });
  }

  @override
  Widget getUrlLoadFailCustomWidget() {
    return XWidgetUtils.getWidgetGestureDetector(
        child: XWidgetUtils.getLayoutContainer(
          alignment:Alignment.center,
          backgroundColor: Colors.white,
          child: XWidgetUtils.getLayoutColumn(
              mainAxisSize:MainAxisSize.min,
              mainAxisAlignment:MainAxisAlignment.center,
              crossAxisAlignment:CrossAxisAlignment.center,
              children: [
                XImageUtils.getImageWidgetWithAsset(
                    'index_no_data_5.png',
                    width: 122,
                    height: 98
                ),
                XWidgetUtils.getWidgetText(
                  '网络不可用,请检查网络连接,点击刷新重试!',
                  padding: XWidgetUtils.getEdgeInsets(0, 10, 0, 0),
                )
              ]
          ),
        ),
        onTap: (){
          //加载失败自定义提示界面,点击重新加载
          XLogUtils.printLog("-----reLoadUrl");
          setState(() {
            isWebViewLoadFailShowCustomWidget=false;
            reLoadUrl(loadFailUrl);
          });
        }
    );
  }


}